﻿using System;
using System.IO;

namespace Rosetta.Default.AddIns.IO
{
    public sealed class DirectoryConverter : Converter
    {
        #region Constructors

        public DirectoryConverter()
            : base("Directory Converter")
        {
            Category = "IO";

            Add<DirectoryInfo, FileInfo[]>("GetAllFiles", GetAllFiles, "directory");
            Add<DirectoryInfo, string, FileInfo[]>("GetFiles", GetFiles, "directory", "searchPattern");
        }

        #endregion

        #region Class Methods

        private static FileInfo[] GetAllFiles([NotNull] DirectoryInfo directory)
        {
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }

            return directory.GetFiles();
        }

        private static FileInfo[] GetFiles([NotNull] DirectoryInfo directory, [NotNull] string searchPattern)
        {
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }
            if (searchPattern == null)
            {
                throw new ArgumentNullException("searchPattern");
            }

            return directory.GetFiles(searchPattern);
        }

        #endregion
    }
}